import { reactive } from 'vue'
// https://cn.vuejs.org/guide/scaling-up/state-management.html

import account  from '../api/account.js'

export const jwt = reactive({
    isLogin: false,
    user: {},
    token: null,
    login(data) {
        this.isLogin = true
        this.user = data.user
        this.token = data.jwt
        console.debug('this.user = ' + this.user)
        console.debug('this.token = ' + this.token)
    },
    logout() {
        account.logout().then(() => {
            this.isLogin = false
            this.user = {}
            this.token = null
            sessionStorage.clear();
        })
    },
})
